package com.link.base.base.accnt.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.link.base.base.accnt.model.Account;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.link.base.base.accnt.model.AcctChange;
import com.link.base.base.accnt.service.AcctChangeService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客户变更
 *
 * @author 阳晓琳
 * @date 2020-10-12 14:25:07
 */
@Controller
@RequestMapping("/link/acctChange")
public class AcctChangeController extends BasicController<AcctChange> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private AcctChangeService acctChangeService;

    @Override
    public BasicService<AcctChange> getBasicService() throws Exception {
        return acctChangeService;
    }

    /**
     * 获取变更前后客户信息
     */
    @RequestMapping(value = "/queryChangeInfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryChangeInfo(@JsonParam AcctChange entity, @JsonParam QueryParams qps, HttpSession session,
                                              HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            AcctChange acctChange = (AcctChange) BasicModel.transformClass(AcctChange.class, qps);
            //安全性設置
            entity.preDealSecurity(request);
            List<AcctChange> list = acctChangeService.queryChangeInfo(entity);
            result.put("success", true);
            result.put("rows", list);
            result.put("total", getCount(acctChange, list.size()));
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("rows", new ArrayList<Account>());
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 选择父对象时的picklist
     */
    @RequestMapping(value = "/acctChangeSubmit", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> acctChangeSubmit(@JsonParam AcctChange entity, @JsonParam QueryParams qps, HttpSession session,
                                               HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            AcctChange acctChange = (AcctChange) BasicModel.transformClass(AcctChange.class, qps);
            //安全性設置
            entity.preDealSecurity(request);
            acctChangeService.acctChangeSubmit(entity);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("rows", new ArrayList<Account>());
            result.put("result", e.getMessage());
        }
        return result;
    }
}